//
//  StwxItemViewModel.m
//  EnvironmentalProtection
//
//  Created by HCreater on 2018/10/23.
//  Copyright © 2018年 HCreater. All rights reserved.
//

#import "StwxItemViewModel.h"

@interface StwxItemViewModel ()

@property (nonatomic, copy) NSString* content;
@property (nonatomic, copy) NSString* goodNum;
@property (nonatomic, copy) NSString* commentNum;
@property (nonatomic, copy) NSString* readLastDate;
@property (nonatomic, copy) NSString* readNum;
@property (nonatomic, copy) NSString* checkResult;
@property (nonatomic, strong) RACCommand* moreCmd;

@end

@implementation StwxItemViewModel

- (instancetype)initWithData:(id)data cellHeight:(CGFloat)cellHeight
{
    self = [super init];
    if (self)
    {
        //        _epInfoData = data;
        
        _data = data;
        
        /// cellHeight+2（2容错）
        _cellHeight = MHUIScaleValue(cellHeight)+2;
        
        @weakify(self);
        [[RACObserve(self, data) distinctUntilChanged] subscribeNext:^(id x)
        {
            @strongify(self);
            
            ArticleListData* curAListData = x;
            
            self.content = curAListData.title;
            self.goodNum = HCStrFormat(@"%d", (int)curAListData.zan);
            self.commentNum = HCStrFormat(@"%d", (int)curAListData.commentCount);
            self.readLastDate = curAListData.addTime;
            self.readNum = HCStrFormat(@"阅读量：%d", (int)curAListData.readCount);
            self.checkResult = curAListData.status == 1 ? @"已发布" : (curAListData.status == 2 ? @"下架" : @"待审核");
            
            self.moreCmd = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input)
            {
                return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber)
                {
                    [subscriber sendNext:nil];
                    [subscriber sendCompleted];
                    
                    return nil;
                }];
            }];
        }];
    }
    
    return self;
}

@end
